﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Text.RegularExpressions;
using System.Data;
using MYNAMESPACE;

namespace final_project
{
    public partial class Manager_Work : Form
    {
        private connect_db con;
        public string nm;
        public string passvalue
        {

            get
            {
                return nm;
            }
            set
            {
                nm = value;
            }
        }
        public Manager_Work()
        {
            InitializeComponent();
        }

        private void Manger_Work_Load(object sender, EventArgs e)
        {
            ID.Text = nm;
            employee ma = new employee();
            ma.setnational_id(Int32.Parse(ID.Text.Trim()));
            con = new connect_db();
            con.sqlquery("select name from Employee where id=(@namep)");
            con.cmd.Parameters.Add("@namep", ma.getnational_id());
            foreach (DataRow dr in con.QueryEx().Rows)
            {

                label1.Text = "wellcome MR/s : " + dr[0].ToString();


            } 
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Hide();
            Assin_Employee AS = new Assin_Employee();
            AS.ShowDialog();
        }

        private void Delete_Click(object sender, EventArgs e)
        {
            // Validating Start code

            if (this.ValidateChildren(ValidationConstraints.Enabled))
            {
                MessageBox.Show("All controls are valid!");
                //Logic to save...
            }
            else
            {
                MessageBox.Show("There are invalid controls on the form.");
                //Return user to form...
            }

            //Validating end code 


            employee em = new employee();
            em.setnational_id(Int32.Parse(Emlpyee_id.Text.Trim()));

            em.setnational_id(Int32.Parse(Emlpyee_id.Text.Trim()));
            con = new connect_db();
            con.sqlquery("select * from Employee where id= (@namep)");
            con.cmd.Parameters.Add("@namep",em.getnational_id());

            // con.sqlnonex();
            int c = 0;
            foreach (DataRow dr in con.QueryEx().Rows)
            {
                c = c + 1;
            }
            if (c == 1)
            {
            con.sqlquery("delete from Employee where id=(@namep)");
            con.cmd.Parameters.Add("@namep", em.getnational_id());
            con.sqlnonex();
            MessageBox.Show("the Accoun is deleted");
           
            }
            else
            {
                MessageBox.Show("not correct");

            }
           

            //con.sqlquery("select * from Employee where id= (@namep) and pass=(@namep1)  and job_type ='manager'");
            //con.cmd.Parameters.Add("@namep", ID.Text.Trim());
            //con.cmd.Parameters.Add("@namep1", Password.Text.Trim());

            
        }

        private void groupBox2_Enter(object sender, EventArgs e)
        {

        }

        private void Emlpyee_id_Validating(object sender, CancelEventArgs e)
        {
            if (string.IsNullOrEmpty(Emlpyee_id.Text))
            {

                e.Cancel = true;
                Emlpyee_id.Focus();
                errorProvider1.SetError(Emlpyee_id, "ID Must Be Entered !");

            }

            else if (!Regex.IsMatch(Emlpyee_id.Text, @"^\d{4}$"))
            {
                e.Cancel = true;
                errorProvider1.SetError(Emlpyee_id, "Valid ID 4 Number");

            }



            else if (Regex.IsMatch(Emlpyee_id.Text, @"^\d{4}$"))
            {
                e.Cancel = false;
                errorProvider1.SetError(Emlpyee_id, "");

            }
            else { }
        }
    }
}
